package com.xnfh.home.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.xnfh.framework.bean.TableImgListBean
import com.xnfh.framework.helper.SumAppHelper
import com.xnfh.home.R
import com.xnfh.image.ImageHelper
import com.xnfh.image.ImageUrl
import com.youth.banner.adapter.BannerAdapter

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2024/1/2 15:07
 * @UpdateUser: ziheng
 * @UpdateDate: 2024/1/2 15:07
 * @UpdateRemark: 更新说明
 */
class ProductImageAdapter(mDatas: List<TableImgListBean?>?) :
    BannerAdapter<TableImgListBean?, ProductImageAdapter.BannerViewHolder>(mDatas) {
    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        return BannerViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_product_image_layout, parent, false)
        )
    }

    override fun onBindView(
        holder: BannerViewHolder?,
        data: TableImgListBean?,
        position: Int,
        size: Int
    ) {

        ImageHelper.instance.loadNetImg(
            SumAppHelper.getApplication(),
            ImageUrl.BASEURL + data?.pathUrl,
            holder?.image,
            com.xnfh.common.R.mipmap.image_error,
            com.xnfh.common.R.mipmap.image_error
        )

        holder?.itemView?.setOnClickListener {
//            val bundle = Bundle()
//            bundle.putSerializable("data", (data as HomeBannerBean))
//            MessageDetailActivity.start(context!!, bundle)
        }
    }


    inner class BannerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var image: ImageView

        init {
            image = view.findViewById(R.id.product_banner_image)
        }
    }
}